<template>
  <div class="login-panel">
    <img src="../../../assets/img/dog.jpg" alt="" class="image" />
    <h1 class="title">后台管理系统</h1>
    <el-tabs type="border-card" stretch v-model="currentTab">
      <el-tab-pane name="login">
        <template #label>
          <span><i class="el-icon-user-solid"></i> 登陆</span>
        </template>
        <login-account ref="accountRef"></login-account>
      </el-tab-pane>
      <el-tab-pane name="register">
        <template #label>
          <span><i class="el-icon-mobile-phone"></i> 注册</span>
        </template>
        <register ref="registerRef"></register>
      </el-tab-pane>
    </el-tabs>

    <div class="account-control">
      <el-checkbox v-model="isKeepPassword">记住密码</el-checkbox>
      <el-link type="primary" :underline="false">忘记密码</el-link>
    </div>
    <el-button type="primary" class="login-btn" @click="handleLoginClick"
      >立即登陆</el-button
    >
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import LoginAccount from './login-account.vue'
import Register from './register.vue'

export default defineComponent({
  components: {
    LoginAccount,
    Register
  },
  setup() {
    const isKeepPassword = ref(true)
    const accountRef = ref<InstanceType<typeof LoginAccount>>()
    const registerRef = ref<InstanceType<typeof Register>>()
    const currentTab = ref<string>('login')

    const handleLoginClick = () => {
      // console.log('立即登陆')
      if (currentTab.value === 'login') {
        accountRef.value?.loginAction(isKeepPassword.value)
      } else {
        // 执行注册的逻辑,调用注册action
      }
    }
    return {
      isKeepPassword,
      accountRef,
      currentTab,
      registerRef,
      handleLoginClick
    }
  }
})
</script>

<style scoped lang="less">
.login-panel {
  width: 320px;
  margin-bottom: 300px;
  img {
    margin: 0 auto;
    width: 320px;
    height: 200px;
  }
  .title {
    text-align: center;
  }
  .account-control {
    margin-top: 8px;
    display: flex;
    justify-content: space-between;
  }
  .login-btn {
    width: 100%;
    margin-top: 8px;
  }
}
</style>
